#include "RenderResource.h"
#include "Runtime/CGI/CGIAccess.h"
#include "Runtime/CGI/Vulkan/VulkanBarriers.h"
#include "Runtime/Thread/RenderingThreadContext.h"

namespace Alice
{
    void RenderResource::InitResource(CGICommandListBase& inCGICmdList)
    {
        InitRHI(inCGICmdList);
    }
    CGIBuffer* RenderResource::CreateRHIBufferInternal(
        CGICommandListBase& RHICmdList,
        const TCHAR* InDebugName,
        const TCHAR* InOwnerName,
        uint32 ResourceCount,
        EBufferUsageFlags InBufferUsageFlags,
        FResourceArrayInterface* ResourceArray,
        bool bWithoutNativeResource)
    {
        const uint32 SizeInBytes = sizeof(Vector3f)*3;//ResourceArray ? ResourceArray->GetResourceDataSize() : 0;
        CGIResourceCreateInfo CreateInfo(InDebugName, ResourceArray);
        CreateInfo.ClassName = InDebugName;
        CreateInfo.OwnerName = InOwnerName;
        CreateInfo.bWithoutNativeResource = bWithoutNativeResource;

        CGIBuffer* Buffer = RHICmdList.CreateBuffer(SizeInBytes, InBufferUsageFlags | EBufferUsageFlags::VertexBuffer, 0, ECGIAccess::VertexOrIndexBuffer | ECGIAccess::SRVMask, CreateInfo);

        //Buffer->SetOwnerName(InOwnerName);
        return Buffer;
    }

    void BeginInitResource(RenderResource* inResource, RenderCommandPipe* inRenderCommandPipe)
    {
        if(true)
        {
            inResource->InitResource(GetImmediateCommandList_ForRenderCommand());
            return ;
        }
        ENQUEUE_RENDER_COMMAND(InitCommand)([inResource](CGICommandListBase & inCGICommandList)
        {
            inResource->InitResource(inCGICommandList);       
        });
    }
}
